package com.mashibing.serviceverificationcode.controller;

import com.mashibing.dto.ResponseResult;
import com.mashibing.responsse.NumberCodeResponse;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class VerificationCodeController {


    @GetMapping("/numberCode/{size}")
    public ResponseResult getVerificationCode (@PathVariable("size") int size){
//        获取验证码
        double numberCode  = (Math.random() * 9 +1) *(Math.pow(10,size-1));
        int resultCode = (int)numberCode;

//        封装返回数据

        NumberCodeResponse numberCodeResponse = new NumberCodeResponse();
        numberCodeResponse.setNumberCode(resultCode);
        ResponseResult result = ResponseResult.success(numberCodeResponse);

        return result;
    }




}
